import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		login: false, //是否登录
		token: '',
		userInfo: {},
		//审批tab参数
		approvalData: '',
		//合同tab参数
		constructorData: ''
	},
	mutations: {
		login(state, provider) {
			state.login = true;
			state.token = provider.token;
			uni.setStorage({
				key: 'token',
				data: provider.token
			})
		},
		logout(state) {
			state.login = false;
			state.token = '';
			state.userInfo = {};
			uni.removeStorage({
				key: 'token'
			});
			uni.removeStorage({
				key: 'userInfo'
			});
		},
		setUserInfo(state, provider) {
			Object.assign(state.userInfo, provider.userInfo);
			uni.setStorage({
				key: 'userInfo',
				data: provider.userInfo
			})
		},
		setApproval(state,provider) {
				state.approvalData=provider
			uni.setStorage({
				key: 'approvalData',
				data: provider
			})
		},
		setConstructor(state, provider) {
				state.constructorData=provider.constructorData
			uni.setStorage({
				key: 'constructorData',
				data: provider.constructorData
			})
		}
	}
})

export default store
